// Read in the data
insheet using "kappa-replication.csv", names

// For each rater, calculate the number of discourses identified by statement
gen tot1=a1+b1+c1+d1
gen tot2=a2+b2+c2+d2

// Create a variable for Rater 1 coding
gen rater1=0
replace rater1=1 if a1==1 & tot1==1
replace rater1=2 if b1==1 & tot1==1
replace rater1=3 if c1==1 & tot1==1
replace rater1=4 if d1==1 & tot1==1
replace rater1=5 if a1==1 & c1==1
replace rater1=6 if a1==1 & d1==1
replace rater1=7 if c1==1 & d1==1
replace rater1=8 if tot1==0

// Create a variable for Rater 2 coding
gen rater2=0
replace rater2=1 if a2==1 & tot2==1
replace rater2=2 if b2==1 & tot2==1
replace rater2=3 if c2==1 & tot2==1
replace rater2=4 if d2==1 & tot2==1
replace rater2=5 if a2==1 & c2==1
replace rater2=6 if a2==1 & d2==1
replace rater2=7 if c2==1 & d2==1
replace rater2=8 if tot2==0

//Label variable and category values
label variable rater1 "Rater 1"
label variable rater2 "Rater 2"
label define rater 1 "A" 2 "B" 3 "C" 4 "D" 5 "A+C" 6 "A+D" 7 "C+D" 8 "None"
label values rater1 rater
label values rater2 rater

// Conduct the Cohen's kappa calculation
kap rater1 rater2
